package com.atguigu.utils;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

public class CountDownLatchDemo1 {
    //倒计时方法CountDownLatch
    public static void main(String[] args) throws InterruptedException {
        CountDownLatch countDownLatch = new CountDownLatch(5);

        for (int i = 1; i <= 5; i++) {
            int finalI = i;
            new Thread(()->{
                System.out.print(Thread.currentThread().getName());
                System.out.println(finalI + "执行了...");
                countDownLatch.countDown();
            }, String.valueOf(i)).start();
        }
//        TimeUnit.SECONDS.sleep(3);
        countDownLatch.await();
        System.out.println(Thread.currentThread().getName() + "最后执行");
        System.out.println("666");
    }
}
